/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package towerdefence.view;

import net.phys2d.math.Vector2f;
import towerdefence.model.StepListener;

/**
 *
 * @author Andreas
 */
public class GLCamera implements StepListener {
    private Vector2f position = new Vector2f(), targetPosition = new Vector2f();
    private float zoom = 1.0f;
    private float targetZoom = 1.0f;
    private GLCore core;
    private static final float UPDATE_SPEED = 10f;

    public GLCamera(GLCore core) {
        this.core = core;
    }
    
    
    public void setPosition(Vector2f position) {
        this.position = position;
    }

    public void setZoom(float zoom) {
        this.targetZoom = zoom;
    }
    
    public void adjustZoom(float change, Vector2f position) {
        targetZoom += change;
    }

    public Vector2f getPosition() {
        return position;
    }
    
    public Vector2f getTranslatePosition() {
        Vector2f translatePos = new Vector2f();
        translatePos.x = position.x - (core.getWidth() / 2) * zoom;
        translatePos.y = position.y - (core.getHeight() / 2) * zoom;
        return translatePos;
    }

    public float getZoom() {
        return zoom;
    }

    @Override
    public void step() {
        if(Math.abs(targetZoom - zoom) > 0.001) {
            zoom += (targetZoom - zoom) / UPDATE_SPEED;
        }
    }
    
}
